
package com.contractmodule.dao;
import com.contractmodule.bean.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import util.*;
public class TbDispatchListProductPriceDAO {
    private Connection conn = null;
    private PreparedStatement pt = null;
    private ResultSet rs = null;
    private boolean flag = false;
    private String sql = "";
    private TbDispatchListProductPrice tbDispatchListProductPrice=null;
    private List<TbDispatchListProductPrice> tbDispatchListProductPriceList=null;

    public boolean add(TbDispatchListProductPrice inTbDispatchListProductPrice){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="insert into Tb_DispatchListProductPrice(DispatchListCode,CompanyProductMiddleId) values(?,?)";
        pt = conn.prepareStatement(sql);
        
        pt.setString(1,inTbDispatchListProductPrice.getDispatchListCode());
        pt.setInt(2,inTbDispatchListProductPrice.getCompanyProductMiddleId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public boolean del(int inDispatchListProductPriceId){
        return UtilDAO.del("Tb_DispatchListProductPrice", "DispatchListProductPriceId", inDispatchListProductPriceId);
    }
    public boolean edit(TbDispatchListProductPrice inTbDispatchListProductPrice){
        try{
            
        conn=ConnectDB.getSqlServerConnection();
        sql="update Tb_DispatchListProductPrice set DispatchListProductPriceId=?,DispatchListCode=?,CompanyProductMiddleId=? where DispatchListProductPriceId=?";
        pt = conn.prepareStatement(sql);
        
        pt.setInt(1,inTbDispatchListProductPrice.getDispatchListProductPriceId());
        pt.setString(2,inTbDispatchListProductPrice.getDispatchListCode());
        pt.setInt(3,inTbDispatchListProductPrice.getCompanyProductMiddleId());
        pt.setInt(4,inTbDispatchListProductPrice.getDispatchListProductPriceId());
        if (pt.executeUpdate() > 0) flag=true;
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return flag;
    }
    public TbDispatchListProductPrice getTbDispatchListProductPriceByDispatchListProductPriceId(int inDispatchListProductPriceId) {
        tbDispatchListProductPrice=null;
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_DispatchListProductPrice where DispatchListProductPriceId=? ";
            pt = conn.prepareStatement(sql);
            pt.setInt(1,inDispatchListProductPriceId);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbDispatchListProductPrice = getTbDispatchListProductPrice(rs);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbDispatchListProductPrice;
    }
    public List<TbDispatchListProductPrice> getTbDispatchListProductPriceAll() {
        tbDispatchListProductPriceList=new ArrayList<TbDispatchListProductPrice>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_DispatchListProductPrice";
            pt = conn.prepareStatement(sql);
            rs = pt.executeQuery();
            while (rs.next()) {
                tbDispatchListProductPriceList.add(getTbDispatchListProductPrice(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbDispatchListProductPriceList;
    }
    public List<TbDispatchListProductPrice> getTbDispatchListProductPriceAll(VskPage vp) {
        tbDispatchListProductPriceList=new ArrayList<TbDispatchListProductPrice>();
        try{
            conn = ConnectDB.getSqlServerConnection();
            sql = "select * from Tb_DispatchListProductPrice";
            vp.setAllCountSql(sql);
            vp.getAllRecordCount(conn, vp.getAllCountSql());
            pt = conn.prepareStatement(vp.processPageSql( "Tb_DispatchListProductPrice", "DispatchListProductPriceId"));
            rs = pt.executeQuery();
            while (rs.next()) {
                tbDispatchListProductPriceList.add(getTbDispatchListProductPrice(rs));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
                        ConnectDB.closeSqlConnection();        }
        return tbDispatchListProductPriceList;
    }
    public TbDispatchListProductPrice getTbDispatchListProductPrice(ResultSet rs) throws Exception{
        TbDispatchListProductPrice tbDispatchListProductPrice = new TbDispatchListProductPrice();
        tbDispatchListProductPrice.setDispatchListProductPriceId(rs.getInt("DispatchListProductPriceId"));
        tbDispatchListProductPrice.setDispatchListCode(rs.getString("DispatchListCode"));
        tbDispatchListProductPrice.setCompanyProductMiddleId(rs.getInt("CompanyProductMiddleId"));
        return tbDispatchListProductPrice;
    }
}
